package com.allwees.bs.module.oms.req.query;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.allwees.bs.core.model.order.wf.order.EOrderState;
import com.allwees.bs.core.modelbase.req.QueryReq;
import com.allwees.bs.module.oms.constant.EOrderQueryType;
import com.allwees.bs.module.oms.entity.Order;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * 订单列表查询参数封装
 *
 * @author yangylsky
 * @since 2019-08-29
 *
 */
@Data
@EqualsAndHashCode(callSuper=false)
public class OrderQueryReq extends QueryReq<Order> {
	// 查询类型
	private EOrderQueryType queryType;

	private String uuid;

	private String keyword;

	private EOrderState state;

	private EOrderState[] states;

	private Date createDateBegin;

	private Date createDateEnd;

	private Date printDateBegin;

	private Date printDateEnd;

	private Date deliverDateBegin;

	private Date deliverDateEnd;

	private Date paymentDateBegin;

	private Date paymentDateEnd;

	/**
	 * 买家ID
	 */
	private String userUuid;

	/**
	 * 订单号
	 */
	private String no;

	/**
	 * CODE
	 */
	private String code;

	/**
	 * 订单来源
	 */
	private String source;


	public void setQueryType(EOrderQueryType queryType){
		this.states = queryType.getStates();
	}

	public final void buildQuery(QueryWrapper<Order> queryWrapper) {
		queryWrapper.eq(StringUtils.isNotBlank(code),"promo_code",code)
				.eq(StringUtils.isNotBlank(source),"platform",source)

				.eq(StringUtils.isNotBlank(userUuid),"user_uuid",userUuid)
				.eq(StringUtils.isNotBlank(no), "no", no)
				.ge( createDateBegin != null, "created_at", createDateBegin)
				.le(createDateEnd != null, "created_at", createDateEnd)
				.in(null != states ,"state", states);

	}
}
